"use strict";
const e = require("../../common/vendor.js"),
  a = require("../../api/request.js"),
  t = require("../../api/cos.js");
require("../../api/my-account.js");
const r = {
    __name: "personal",
    setup(r) {
      e.hooks.locale("zh-cn"), e.onMounted((() => {
        const {
          avatarUrl: a,
          backdrop: t,
          nickname: r,
          gender: n,
          birthday: i,
          city: c
        } = e.index.getStorageSync("userInfor");
        o.avatarUrl = a, o.backdrop = t, o.nickname = r, o.gender = n, o.birthday = i, o.city = c
      }));
      const o = e.reactive({
        backdrop: "",
        avatarUrl: "",
        nickname: "",
        gender: "",
        birthday: "",
        city: ""
      });
      async function n(a) {
        e.wx$1.chooseMedia({
          count: 3,
          mediaType: ["image"],
          sizeType: ["compressed"],
          sourceType: ["album", "camera"],
          success: async r => {
            e.wx$1.showLoading({
              title: "上传中",
              mask: !0
            });
            try {
              const e = await t.upLoadCos(r.tempFiles);
              0 === a ? o.avatarUrl = e[0] : o.backdrop = e[0]
            } catch (n) {
              console.log(n), e.wx$1.showToast({
                title: "上传失败",
                icon: "error",
                duration: 800
              })
            }
          }
        })
      }

      function i(e) {
        o.gender = "0" === e.detail.value ? "男" : "女"
      }
      const c = e.hooks().format("YYYY-MM-DD"),
        d = e.ref("1930-01-01"),
        s = e.ref(c);

      function l(e) {
        o.birthday = e.detail.value
      }

      function u(e) {
        let a = "";
        e.detail.value.forEach((e => a += e)), o.city = a
      }
      async function y() {
        e.wx$1.showLoading({
          title: "更新中",
          mask: !0
        });
        const t = await a.requestApi("/modify_the_user", o, "POST"),
          {
            age: r,
            avatarUrl: n,
            backdrop: i,
            birthday: c,
            city: d,
            gender: s,
            nickname: l
          } = t.data,
          u = e.index.getStorageSync("userInfor");
        u.age = r, u.avatarUrl = n, u.backdrop = i, u.birthday = c, u.city = d, u.gender = s, u.nickname = l, e.wx$1.setStorageSync("userInfor", u), e.index.$emit("uploadUserdata", !0), e.wx$1.navigateBack({
          delta: 1
        })
      }
      return (a, t) => ({
        a: o.backdrop,
        b: o.avatarUrl,
        c: e.o((e => n(0))),
        d: e.o((e => n(1))),
        e: o.nickname,
        f: e.o((e => o.nickname = e.detail.value)),
        g: o.gender,
        h: e.o((e => o.gender = e.detail.value)),
        i: e.o(i),
        j: ["男", "女"],
        k: o.birthday,
        l: e.o((e => o.birthday = e.detail.value)),
        m: e.o(l),
        n: d.value,
        o: s.value,
        p: o.city,
        q: e.o((e => o.city = e.detail.value)),
        r: e.o(u),
        s: e.o(y)
      })
    }
  },
  o = e._export_sfc(r, [
    ["__scopeId", "data-v-2b8ded31"]
  ]);
wx.createPage(o);